package com.example.administrator.liveapp.wxapi;


import com.example.administrator.liveapp.R;
import com.example.administrator.liveapp.activity.BookingDetailsPage;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
	public static final String APP_ID = "wxfbcebe26b18a4bcc";
	private IWXAPI api;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		api = WXAPIFactory.createWXAPI(this, APP_ID);
		api.handleIntent(getIntent(), this);
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
		api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {

	}

	@Override
	public void onResp(BaseResp resp) {
		switch (resp.errCode) {
			case BaseResp.ErrCode.ERR_OK:
				// 支付成功
				Toast.makeText(this,"支付成功",Toast.LENGTH_SHORT).show();
				// 广播通知刷新
				Intent intent = new Intent();
				intent.setAction("action.refreshFriend");
				sendBroadcast(intent);
				break;
			case BaseResp.ErrCode.ERR_USER_CANCEL:
				// 支付取消
				Toast.makeText(this,"支付取消",Toast.LENGTH_SHORT).show();
				// 广播通知刷新
				Intent intent2 = new Intent();
				intent2.setAction("action.refreshFriend");
				sendBroadcast(intent2);
				break;
			case BaseResp.ErrCode.ERR_AUTH_DENIED:
				// 发送被拒绝
				Toast.makeText(this,"发送被拒绝",Toast.LENGTH_SHORT).show();
				break;
			default:
				// 支付失败
				Toast.makeText(this,"支付失败",Toast.LENGTH_SHORT).show();
				break;
		}
		WXPayEntryActivity.this.finish();
	}

}